Skip to content

Fix document registry creating duplicate buckets for projects with different pathsBasePath#63229

Closed
ekazakov14 wants to merge 1 commit intomicrosoft:mainfrom
ekazakov14:fix/exclude-pathsBasePath-from-document-registry-key
Closed

Fix document registry creating duplicate buckets for projects with different pathsBasePath#63229
ekazakov14 wants to merge 1 commit intomicrosoft:mainfrom
ekazakov14:fix/exclude-pathsBasePath-from-document-registry-key

Conversation

@ekazakov14
Copy link

Fixes SourceFile cache reuse between projects.

I couldn't find an existing issue related to this. I don't expect this to be merged given the current state of the repo, but I'm publishing the change for visibility since I'll be applying it as a local patch in our projects.

Problem

monorepo/
├── packages/projectA/tsconfig.json   (pathsBasePath = "/monorepo/packages/projectA")
├── packages/projectB/tsconfig.json   (pathsBasePath = "/monorepo/packages/projectB")
└── shared/utils.d.ts                 (used by both projects)

Both projects have identical compiler options, only pathsBasePath differs.

┌─ Document Registry (before fix) ──────────────────────────────────────────┐
│                                                                           │
│  Bucket key: "...options...|/monorepo/packages/projectA"                  │
│    └─ shared/utils.d.ts  →  SourceFile instance A                        │
│                                                                           │
│  Bucket key: "...options...|/monorepo/packages/projectB"                  │
│    └─ shared/utils.d.ts  →  SourceFile instance B  ← duplicate!          │
│                                                                           │
└───────────────────────────────────────────────────────────────────────────┘

┌─ Document Registry (after fix) ───────────────────────────────────────────┐
│                                                                           │
│  Bucket key: "...options..."                                              │
│    └─ shared/utils.d.ts  →  SourceFile instance A  ← shared by both      │
│                                                                           │
└───────────────────────────────────────────────────────────────────────────┘

Summary

When multiple projects in a monorepo share the same compiler options but reside in different directories, the document registry creates separate buckets for each project due to pathsBasePath being included in the bucket key. This causes duplicate SourceFile instances for shared files, increasing memory consumption.

The pathsBasePath property is derived from the paths compiler option, which itself is not marked as affectsSourceFile. Therefore pathsBasePath should not participate in the document registry bucket key either.

Changes

Move pathsBasePath from the shared getKeyForCompilerOptions into getRedirectsCacheKey, so it only affects the module resolution cache where it is actually needed.

Impact

In large monorepos with many projects sharing the same compiler options, this reduces memory usage by allowing the document registry to reuse SourceFile instances across projects instead of creating duplicates per pathsBasePath. It also slightly speeds up initialization of new projects (processRootFiles) since cached SourceFile instances are reused instead of being re-parsed.

@typescript-bot
Copy link
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants